import json
from framework.event import Event
from datetime import datetime, date, time

class JSONEventEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, Event):
            return encode_Event(o)
        if isinstance(o, (datetime, date, time)):
            return encode_datetime(o)
        return super(JSONEventEncoder, self).default(o)

def encode_datetime(dt_object):
    return dt_object.isoformat()

def encode_Event(event):
    return {
        'title': event.title,
        'start_datetime': event.start_datetime,
        'end_datetime': event.end_datetime,
        'description': event.description,
        'price': event.price
    }
